// TODO: CODE REVIEW & CLEANUP!
//
// Rockers.cs
//
// Implements VerticalRockerOverlay and related types.
//

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using HomeUX.ClientControlSupport;

namespace HomeUX.Controls
{

/// <summary>
/// A <r>VerticalRockerOverlay</r> is essentially a label that can be placed above a pair of
/// blank (no content) 50-pixel-tall <r>TouchButton</r> controls, to provide a common label for
/// the two controls.  The goal (not completely achieved here) is something like a rocker
/// switch.  The only real functionality of <r>VerticalRockerOverlay</r> is to "grey out" when
/// one of the two buttons is disabled (the assumption is that both will be disabled when either
/// is disabled).
/// </summary>
///
[TemplateVisualState(GroupName = CommonStatesName, Name = NormalName)]
[TemplateVisualState(GroupName = CommonStatesName, Name = DisabledName)]
public class VerticalRockerOverlay : Control
{
    const string CommonStatesName = "CommonStates";
    const string NormalName = "Normal";
    const string DisabledName = "Disabled";

    public static readonly DependencyProperty TextProperty =
        DependencyProperty.Register("Text", typeof(string), typeof(VerticalRockerOverlay), null);

    public string Text
    {
        get
        {
            return (string)GetValue(TextProperty);
        }
        set
        {
            SetValue(TextProperty, value);
        }
    }

    public VerticalRockerOverlay()
    {
        DefaultStyleKey = typeof(VerticalRockerOverlay);
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        IsEnabledChanged += VerticalRockerOverlay_IsEnabledChanged;

        UpdateVisualState(false);
    }

    void VerticalRockerOverlay_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        UpdateVisualState(true);
    }

    void UpdateVisualState(bool useTransitions)
    {
		if (IsEnabled)
			VisualStateManager.GoToState(this, NormalName, useTransitions);
        else
			VisualStateManager.GoToState(this, DisabledName, useTransitions);
	}
}

}

